package me.xplabs 
{
	import flash.display.Sprite;
	import flash.display.Stage;
	import me.xplabs.engine.GameManager;
	import me.xplabs.engine.time.TimeManager;
	import me.xplabs.loader.ResLibrary;
	import me.xplabs.ui.baseui.UIManager;
	import me.xplabs.utils.Domain;
	import me.xplabs.utils.FPS;
	/**
	 * ...
	 * @author xiaohan
	 */
	public class Globals 
	{
		
		public static const stageW:int = 700;
		public static const stageH:int = 600;
		public static const centerW:int = stageW * .5;
		public static const centerH:int = stageH * .5;
		public static var gameManager:GameManager;
		public static var timeManager:TimeManager;
		public static var suspendTime:TimeManager;
		public static var lib:ResLibrary;
		public static var ui:UIManager;
		public static var domain:Domain;
		
		private static var _soleIdObj:Object;
		
		public static const cellW:int = 15;
		public static const cellH:int = 15;
		static public var gameLayer:Sprite;
		static public var uiLayer:Sprite;
		static public var topLayer:Sprite;
		
		private static var _stage:Stage;
		
		static public var eventType:String;
		public function Globals() 
		{
			
		}
		public static function init(stage:Stage):void
		{
			
			topLayer = new Sprite();
			uiLayer = new Sprite();
			gameLayer = new Sprite();
			stage.addChild(gameLayer);
			stage.addChild(uiLayer);
			stage.addChild(topLayer);
			
			var fps:FPS = new FPS(670, 0, 0x22E348);
			topLayer.addChild(fps);
			
			gameManager = new GameManager();
			gameManager.setStage(stage);
			gameManager.startUpdate();
			
			timeManager = new TimeManager();
			gameManager.addUpdate(timeManager.update);
			
			suspendTime = new TimeManager();
			gameManager.addDataUpdate(suspendTime.update);
			
			lib = new ResLibrary();
			domain = new Domain();
			ui = new UIManager();
			
			_soleIdObj = new Object();
			_stage = stage;
			
		}
		//public static function startTimeManager():void
		//{
			//gameManager.addUpdate(timeManager.update);
		//}
		
		//public static function stopTimeManager():void
		//{
			//gameManager.delUpdate(timeManager.update);
		//}
		
		//public static function stopGameDataUpdate():void
		//{
			//
		//}
		//public static function startGameDataUpdate():void
		//{
			//
		//}
		
		/**
		 * 获取唯一ID
		 */
		public static function get soleId():uint
		{
			var random:uint = uint(Math.random() * 100000 + 1);
			if (_soleIdObj[random] != null) return soleId;
			_soleIdObj[random] = random;
			return random;
		}
		/**
		 * 删除唯一ID
		 * @param	p_id
		 */
		public static function delSoleId(p_soleId:uint):void
		{
			delete _soleIdObj[p_soleId];
		}
	}
}